import { NCountdown } from "naive-ui";
import type { CountdownProps, CountdownInst } from "naive-ui";
import type { HTMLAttributes } from "vue";

export type CountdownFactoryConstructorType = {
  props?: CountdownProps;
  attrs?: HTMLAttributes;
};
export class CountdownFactory {
  private attrs: HTMLAttributes = {};
  private props: CountdownProps = {};
  private domRef: CountdownInst | null = null;

  constructor(data?: CountdownFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
  }

  setProps(props: CountdownProps) {
    this.props = props;
    return this;
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  reset() {
    this.domRef?.reset();
  }

  create() {
    return (
      <NCountdown
        ref={(el: HTMLElement) => {
          this.domRef = el as unknown as CountdownInst;
        }}
        {...this.attrs}
        {...this.props}
      ></NCountdown>
    );
  }
}
